package com.xuelang;

import com.alibaba.fastjson2.JSON;
import com.xuelang.pipeline.client.application.dto.ApplicationDTO;
import com.xuelang.pipeline.client.application.dto.ComponentDTO;
import com.xuelang.pipeline.client.common.result.ApiResult;
import com.xuelang.pipeline.client.common.result.PageRecord;
import com.xuelang.pipeline.client.pipeline.dto.PipelineDTO;
import com.xuelang.pipeline.entry.application.ApplicationController;
import com.xuelang.pipeline.entry.application.ApplicationsController;
import com.xuelang.pipeline.entry.application.ComponentController;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertNotNull;


@Slf4j
@EnableCaching
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = SpringbootApp.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class ApplicationsControllerTest {


    @Autowired
    private ApplicationsController applicationsController;


    @BeforeEach
    public void setUp() {
    }



    @Test
    public void testQueryApplicationsByUserId() {
        PageRecord<PipelineDTO> pageRecord = new PageRecord<>();

        ApiResult<List<Map<String, Object>>> result = applicationsController.queryApplicationsByUserId("");

        log.info(JSON.toJSONString(result));

        assertNotNull(result.getData());

        Object id = ((Map)((List)result.getData().get(0).get("applicationList")).get(0)).get("applicationId");

        ApiResult<Map<String, Object>> component = applicationsController.queryComponentByid(String.valueOf(id));

        log.info("queryById dto : {}", JSON.toJSONString(component));

        assertNotNull(result.getData());

    }


}
